import 'package:flutter/foundation.dart';
import 'package:lib_core/lib_core.dart';
import 'package:lib_core/logger/gt_logger_model.dart';

import '../gt_logger_host_api.dart';
import './gt_logger_base_destination.dart';

/// Author: Shper
/// Created: 2024/2/01
class GTLoggerRecoveryDestination extends GTLoggerBaseDestination {

  /// 与原生交互通道
  final GTLoggerHostApi _loggerHostApi = GTLoggerHostApi();

  @override
  bool ignoreLog(GTLoggerModel logModel) {
    // VERBOSE、DEBUG级别的日志强制不回捞
    if (!logModel.isRecovery || logModel.level.index <= GTLoggerLevel.debug.index) {
        return true;
    }
    // 默认不忽略
    return false;
  }

  @override
  void handleLog(GTLoggerModel logModel) {
    // 日志回捞
    _loggerHostApi.logRecovery(logModel.level.name, "GTFlutter", logModel.message, logModel.fileName, logModel.funcName, logModel.lineNo);
  }

}